


//怎么使用

/**
 * 
 * @param {Function} fn 这个是回调函数,通过懒加载函数,判定滚动条要到达边界阈值的时候,回调这个函数
 * @param {Number} threshold 滚动条到底部的边界阈值
 */

function lazyLoad(fn, threshold = 100) {

    let flag = true;//开关是开启的

    window.onscroll = function () {
        //获取关键属性 

        let scrollTop = document.documentElement.scrollTop;

        let clientHeight = document.documentElement.clientHeight;

        let scrollHeight = document.documentElement.scrollHeight;


        let scrollBottom = scrollHeight - (scrollTop + clientHeight)

        if (scrollBottom <= threshold) {
            if (flag) {
                flag = false;//把开关关掉
                fn()
            }
        } else {
            //把开关打开
            flag = true;
        }
    }
}

